package com.atguigu.gmall.order.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/***
 * 订单退款消息队列配置
 */
@Component
public class OrderRefundRabbitConfig {

    /**
     * 创建交换机
     * @return
     */
    @Bean("orderRefundExchange")
    public Exchange orderRefundExchange(){
        return ExchangeBuilder.directExchange("order_refund_exchange").build();
    }

    /**
     * 创建队列
     * @return
     */
    @Bean("orderRefundQueue")
    public Queue orderRefundQueue(){
        return QueueBuilder.durable("order_refund_queue").build();
    }

    /**
     * 绑定
     */
    @Bean
    public Binding binding(@Qualifier("orderRefundExchange") Exchange orderRefundExchange,
                           @Qualifier("orderRefundQueue") Queue orderRefundQueue){
        return BindingBuilder.bind(orderRefundQueue).to(orderRefundExchange).with("order.refund").noargs();
    }
}
